package com.example.wechat.csdnandroid.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.example.wechat.csdnandroid.fragment.LocalVideoFragment;

import java.util.ArrayList;

public class ViewPagerFragmentPagerAdapter extends FragmentPagerAdapter {
    private ArrayList<String> listTitle;

    public ViewPagerFragmentPagerAdapter(@NonNull FragmentManager fm, ArrayList<String> listTitle) {
        super(fm);
        this.listTitle = listTitle;
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return LocalVideoFragment.newInstance(position, listTitle.get(position));
    }

    @Override
    public int getCount() {
        return listTitle == null ? 0 : listTitle.size();
    }

    //此方法用来显示tab的名字
    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        if (listTitle == null) {
            return super.getPageTitle(position);
        } else {
            return listTitle.get(position % listTitle.size());
        }
    }
}
